// -----------------------------------------------------------------------
//  <copyright file="EntityConfigurationBase.cs" company="LiuliuSoft">
//      Copyright (c) 2022-2024 DaprPlus. All rights reserved.
//  </copyright>
//  <site>https://dapr.plus</site>
//  <last-editor>郭明锋</last-editor>
//  <last-date>2024/12/24 21:12</last-date>
// -----------------------------------------------------------------------

using Microsoft.EntityFrameworkCore.Metadata.Builders;


namespace DaprPlus.EntityFrameworkCore;

/// <summary>
/// 数据实体映射配置基类
/// </summary>
/// <typeparam name="TEntity">实体类型</typeparam>
public abstract class EntityConfigurationBase<TEntity> : IEntityTypeConfiguration<TEntity>, IEntityRegister
    where TEntity : class
{
    /// <summary>
    /// 重写以实现实体类型各个属性的数据库配置
    /// </summary>
    /// <param name="builder">实体类型创建器</param>
    public abstract void Configure(EntityTypeBuilder<TEntity> builder);

    /// <summary>
    /// 获取 相应的实体类型
    /// </summary>
    public virtual Type EntityType => typeof(TEntity);

    /// <summary>
    /// 将当前实体类映射对象注册到数据上下文模型构建器中
    /// </summary>
    /// <param name="modelBuilder">上下文模型构建器</param>
    public void RegisterTo(ModelBuilder modelBuilder)
    {
        modelBuilder.ApplyConfiguration(this);
    }
}
